﻿using System.Diagnostics;

namespace orleans_demo.Filter
{
    public class PerformanceInterceptor : IIncomingGrainCallFilter
    {
        private readonly ILogger<PerformanceInterceptor> _logger;

        public PerformanceInterceptor(ILogger<PerformanceInterceptor> loggerFactory)
        {
            _logger = loggerFactory;
        }
        public async Task Invoke(IIncomingGrainCallContext context)
        {
            var stopwatch = Stopwatch.StartNew();
            await context.Invoke();
            stopwatch.Stop();

            _logger.LogInformation($"{context.Grain.GetType().Name},{context.MethodName},{stopwatch.ElapsedMilliseconds}");
        }
    }
}
